package demo.java.java8.Lambdas.demo6;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import org.apache.commons.validator.ISBNValidator;

import demo.java.java8.Lambdas.demo4.Dish;
import demo.java.java8.Lambdas.demo5.Test;

/**
 * 收集器-分区
 * @author songfeifei
 *
 */
public class CollectorPartition {

	public static void main(String[] args) {
		
//		//分区函数
//		Map<Boolean,List<Dish>> partitionedMenu=Test.menu.stream()
//				.collect(Collectors.partitioningBy(Dish::isVegetarian));
//		System.out.println(partitionedMenu);
//		
//		//通过map键找到对应的值
//		List<Dish> vegetarianDishes=partitionedMenu.get(true);
//		System.out.println(vegetarianDishes);
//		vegetarianDishes=partitionedMenu.get(false);
//		System.out.println(vegetarianDishes);
//		
//		vegetarianDishes=Test.menu.stream().filter(Dish::isVegetarian)
//				.collect(Collectors.toList());
//		System.out.println(vegetarianDishes);
//		
//		//分区后分别按照类型分组
//		Map<Boolean,Map<Dish.Type,List<Dish>>> vegetarianDishesByType=
//				Test.menu.stream()
//				.collect(Collectors.partitioningBy(Dish::isVegetarian,
//						Collectors.groupingBy(Dish::getType))
//						);
//		System.out.println(vegetarianDishesByType);
//		
//		//分区后找到热量最高的Dish
//		Map<Boolean,Dish> mostCaloricPartitionedByVetarian=
//				Test.menu.stream().collect(
//						Collectors.partitioningBy(
//								Dish::isVegetarian, 
//								Collectors.collectingAndThen(
//										Collectors.maxBy(Comparator.comparing(Dish::getCalories)), 
//										Optional::get
//										)
//								));
//		System.out.println(mostCaloricPartitionedByVetarian);
		
		
		
		
	}
	
	
}
